package com.link.base.base.user.service;

import com.link.base.base.user.dao.mybatis.mapper.OauthTokenMapper;
import com.link.base.base.user.model.OauthToken;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xjt
 * @description: OA登录认证token
 * @date 2024/10/15 15:24
 */
@Service(value = "oauthTokenService")
public class OauthTokenServiceImpl extends BasicServiceImpl<OauthToken> implements OauthTokenService {

    @Resource
    private OauthTokenMapper oauthTokenMapper;

    @Override
    public BasicMapper<OauthToken> getBasicMapper() {
        return oauthTokenMapper;
    }


    @Override
    public void addOauthToken(OauthToken oauthToken) throws Exception {
        if (null == oauthToken.getId()) {
            oauthToken.setId(this.keyGenerateService.keyGenerate());
        }
        oauthTokenMapper.addOauthToken(oauthToken);
    }

    @Override
    public OauthToken queryByToken(String oauthToken) throws Exception {
        OauthToken otoken = oauthTokenMapper.queryByToken(oauthToken);
        if (null != otoken) {
            oauthTokenMapper.updateById(otoken.getId());
        }
        return otoken;
    }



}
